// import './assets/main.css'

import { createApp } from 'vue'
import { createPinia } from 'pinia'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import V3DragZoom from "v3-drag-zoom";
import "v3-drag-zoom/dist/style.css";

import App from './App.vue'
import router from './router'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import Tres from '@tresjs/core'
import TlbsMap from 'tlbs-map-vue'

import initModel from '@/components/init-model/init-model.vue'

const app = createApp(App)

const loadTMapScript = () => {
    return new Promise((resolve, reject) => {
        const script = document.createElement('script');
        script.src = 'https://map.qq.com/api/gljs?v=1.exp&key=PZMBZ-S42EW-AFFRY-33VEP-VMRVJ-75BHQ'; // 使用实际的腾讯地图 SDK URL
        script.onload = () => resolve();
        script.onerror = () => reject(new Error('Failed to load TMap SDK'));
        document.head.appendChild(script);
    });
};

loadTMapScript()
    .then(() => {
        // 确保 SDK 加载完成后再将 TMap 赋值给全局属性
        app.config.globalProperties.$TMap = window.TMap;
        // console.log('TMap--->', app.config.globalProperties.$TMap);
    })
    .catch((error) => {
        console.error(error);
    });

// app.mount('#app');



for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
}

// 全局注册组件
app.component('init-model', initModel)
// 全局注册插件
app.use(ElementPlus).use(createPinia()).use(router).use(Tres).use(TlbsMap).use(V3DragZoom)

app.mount('#app')
